<!doctype html>
<html class="no-js">
<head>
    <link rel="stylesheet" href="${rootPath!''}/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="${rootPath!''}/assets/css/admin.css">
</head>
<body style="width: 100%;height: 100%;">
<!-- content start -->
<div class="admin-content">

    <!-- 导航 开始 -->
    <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">${gym.gymName}</strong> <small>(剩余${gym.counts}，已预约${gym.yuyue}，共计${gym.totals})</small></div>
    </div>
    <!-- 导航 结束 -->

    <!-- 功能键和导航 开始 -->
    <div class="am-g">

        <!-- 左边，功能键开始 -->
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <%if(so.hasPermission("GymController.addMd")){%>
                    <button onclick="openAddMdModal();" type="button" class="am-btn am-btn-success"><span class="am-icon-plus"></span> 新增门店</button>
                    <%}%>
                    <%if(so.hasPermission("GymController.exportAll")){%>
                        <a href="${rootPath!''}/gym/exportAll?gymId=${gym.gymId}" class="am-btn am-btn-success" > 导出所有</a>
                    <%}%>
                </div>
            </div>
        </div>

        <form>
            <input type="hidden" name="gymId" value="${gym.gymId}">
            <button type="button" onclick="history.go(-1);" class="am-btn am-btn-primary"><span class="am-icon-arrow-left"></span> 返回</button>
        </form>
    </div>
    <!-- 功能键和导航 结束 -->

    <!-- 内容 开始 -->
    <div class="am-g">
        <div class="am-u-sm-12">

            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr class="am-active">
                        <th class="table-check"><input type="checkbox" onclick="checkbox( this.checked ,'checkbox_list')" /></th>
                        <th class="table-title">门店名</th>
                        <th class="table-title">门店地址</th>
                        <th class="table-title">联系电话</th>
                        <th class="table-title">已使用</th>
                        <th class="table-title">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <%
                    for(data in list){
                    %>
                    <tr>
                        <td><input type="checkbox" value="${data.id}" class="checkbox_list" /></td>
                        <td> ${data.neckName} </td>
                        <td> ${data.addr} </td>
                        <td> ${data.mobile} </td>
                        <td> ${data.used}</td>
                        <td>
                            <button type="button" onclick="openPs(${data.id},'${data.neckName}');" > 重置密码</button>
                            <button type="button" onclick="openInfo(${data.id},'${data.neckName}','${data.addr}','${data.mobile}');" > 修改信息</button>
                            <button type="button" onclick="openUseList(${data.id});">使用记录</button>
                           <!-- <a href="javascript:openPs(${data.id},'${data.neckName}','${data.addr}','${data.mobile}');" class="am-btn am-btn-default am-btn-xs am-text-secondary">重置密码</a>
                            <a href="javascript:openInfo(${data.id},'${data.neckName}');" class="am-btn am-btn-default am-btn-xs am-text-warning am-hide-sm-only">修改信息</a>
                            <a href="javascript:openUseList(${data.id});" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"> 使用记录</a>-->
                        </td>
                    </tr>
                    <%}%>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>

<div class="am-modal am-modal-alert" tabindex="-2" id="addMd-alert">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">新增门店</div>
        <div class="am-modal-bd">
            <div class="am-modal-bd">
                <div class="am-g">
                    <div class="am-u-sm-4">门店名</div>
                    <div class="am-u-sm-8">
                        <input type="text" name="neckName" data-foolish-msg="门店名,不能为空！" required placeholder="输入门店名。">
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-4">登录名</div>
                    <div class="am-u-sm-8">
                        <input type="text" name="userName" data-foolish-msg="登录名,不能为空！" required placeholder="输入登录名。">
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-4">初始密码</div>
                    <div class="am-u-sm-8">
                        <input type="hidden" name="passWord" >
                        <input type="password" id="passWord" required placeholder="一次机会，请牢记...">
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-4">联系电话</div>
                    <div class="am-u-sm-8">
                        <input type="text" name="mobile" placeholder="输入联系电话 ">
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-4">门店地址</div>
                    <div class="am-u-sm-8">
                        <input type="text"  name="addr" placeholder="输入地址">
                    </div>
                </div>
            </div>
        </div>
        <div class="am-modal-footer">
            <span class="am-modal-btn" onclick="addMd();" style="background-color: blue;color: white">确认</span>
            <span class="am-modal-btn" data-am-modal-cancel>取消</span>
        </div>
    </div>
</div>


<div class="am-modal am-modal-alert" tabindex="-2" id="ps-alert">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">重置密码</div>
        <div class="am-modal-bd">
            <div class="am-modal-bd">
                <div class="am-g">
                    <div class="am-u-sm-4">门店名</div>
                    <div class="am-u-sm-8">
                        <input type="hidden" id="psUserId">
                        <input type="text" id="neckName" disabled readonly>
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-4">输入密码</div>
                    <div class="am-u-sm-8">
                        <input type="password" id="passWord1"  required placeholder="输入密码。">
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-4">确认密码</div>
                    <div class="am-u-sm-8">
                        <input type="hidden" id="passWord3" >
                        <input type="password" id="passWord2" required placeholder="确认密码.">
                    </div>
                </div>
            </div>
        </div>
        <div class="am-modal-footer">
            <span class="am-modal-btn" onclick="updatePs();" style="background-color: blue;color: white">确认</span>
            <span class="am-modal-btn" data-am-modal-cancel>取消</span>
        </div>
    </div>
</div>

<div class="am-modal am-modal-alert" tabindex="-2" id="info-alert">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">修改信息</div>
        <div class="am-modal-bd">
            <div class="am-modal-bd">
                <div class="am-g">
                    <div class="am-u-sm-3">门店名</div>
                    <div class="am-u-sm-9">
                        <input type="hidden" id="info-userId">
                        <input type="text" id="info-neckName" placeholder="输入门店名 " style="width:100%;">
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-3">电话</div>
                    <div class="am-u-sm-9">
                        <input type="text" id="info-mobile" placeholder="输入联系电话 " style="width:100%;">
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-3">地址</div>
                    <div class="am-u-sm-9">
                        <input type="text"  id="info-addr" placeholder="输入地址" style="width:100%;">
                    </div>
                </div>
            </div>
        </div>
        <div class="am-modal-footer">
            <span class="am-modal-btn" onclick="updateInfo();" style="background-color: blue;color: white">确认</span>
            <span class="am-modal-btn" data-am-modal-cancel>取消</span>
        </div>
    </div>
</div>


<button style="display: none" id="uselogBtn"
        type="button"
        class="am-btn am-btn-primary"
        data-am-modal="{target: '#uselog'}">

</button>

<div class="am-modal am-modal-alert" tabindex="-1" id="uselog">
    <div class="am-modal-dialog">
        <div class="am-modal-hd" id="uselogcontent"></div>
        <div class="am-modal-footer">
            <span class="am-modal-btn" id="useConfig" onclick="toPage()">确定</span>
        </div>
    </div>
</div>
<!-- content end -->
<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="${rootPath}/assets/js/polyfill/rem.min.js"></script>
<script src="${rootPath}/assets/js/polyfill/respond.min.js"></script>
<script src="${rootPath}/assets/js/amazeui.legacy.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="${rootPath}/assets/js/jquery.min.js"></script>
<script src="${rootPath}/assets/js/amazeui.min.js"></script>
<!--<![endif]-->
<script src="${rootPath}/assets/js/app.js"></script>
<script type="text/javascript" src="${rootPath}/ext/js/jquery.md5.js"></script>
<script type="text/javascript">
    function openInfo(userId,neckName,addr,mobile){
        $("#info-userId").val(userId);
        $("#info-neckName").val(neckName);
        $("#info-addr").val(addr);
        $("#info-mobile").val(mobile);
        $("#info-alert").modal("open");
    }

    function openPs(userId,neckName){
        $("#psUserId").val(userId);
        $("#neckName").val(neckName);
        $("#passWord1").val('');
        $("#passWord2").val('');
        $("#ps-alert").modal("open");
    }

    function openUseList(userId){
        location.href = "${rootPath}/gym/useList?userId="+userId;
    }
    function toPage(){
        var gymId = $( "input[name='gymId']" ).val();
        location.href = "${rootPath}/gym/list?gymId="+gymId;
    }
    function openAddMdModal(){
        $("#addMd-alert").modal("open");
    }
    function addMd(){
        if( $( "input[name='userName']" ).val() == '' ) {
            window.top.tips( "登录名不能为空！" );
            $("input[name='userName']").focus() ;
            return ;
        }
        if( $( "#passWord" ).val() == '' ) {
            window.top.tips( "密码不能为空！" );
            $("#passWord").focus() ;
            return ;
        }else{
            $("input[name='passWord']").val( $.md5( $.md5( $( "#passWord" ).val() ) ) );
        }
        var userName = $( "input[name='userName']" ).val();
        var neckName = $( "input[name='neckName']" ).val();
        var passWord = $( "input[name='passWord']" ).val();
        var mobile = $( "input[name='mobile']" ).val();
        var addr = $( "input[name='addr']" ).val();
        var gymId = $( "input[name='gymId']" ).val();
        $.post( "${rootPath}/gym/addMd", {"userName":userName,"neckName":neckName,"passWord":passWord,"mobile":mobile,"addr":addr,"gymId":gymId} , function ( data ) {
            if ( data.status == 1 ) {
                $('#addCount-alert').modal('close');
            }
            $( "input[name='userName']" ).val('');
            $( "input[name='neckName']" ).val('');
            $( "input[name='passWord']" ).val('');
            $( "#passWord" ).val('');
            $( "input[name='mobile']" ).val('');
            $( "input[name='addr']" ).val('');
            $('#uselogcontent').text( data.msg);
            $('#uselogBtn').click();
        }, "json" );
    }

    function updatePs(){
        if( $( "#passWord1" ).val() == '' ||  $( "#passWord2" ).val() == '') {
            window.top.tips( "请输入密码！" );
            return ;
        }

        if( $( "#passWord1" ).val() !=  $( "#passWord2" ).val()) {
            window.top.tips( "2次密码不相同！" );
            return ;
        }

        $("#passWord3").val( $.md5( $.md5( $( "#passWord1" ).val() ) ) );
        var userId = $( "#psUserId" ).val()
        var passWord = $( "#passWord3" ).val();
        $.post( "${rootPath}/gym/updatePs", {"passWord":passWord,"userId":userId} , function ( data ) {
            if ( data.status == 1 ) {
                $('#ps-alert').modal('close');
            }
            $('#uselogcontent').text( data.msg);
            $('#uselogBtn').click();
        }, "json" );
    }

    function updateInfo(){
        if( $( "#info-neckName" ).val() == '') {
            window.top.tips( "请输入门店名！" );
            return ;
        }

        if( $( "#info-addr" ).val() == '') {
            window.top.tips( "请输入地址！" );
            return ;
        }

        if( $( "#info-mobile" ).val() == '') {
            window.top.tips( "请输入联系电话！" );
            return ;
        }

        var userId = $( "#info-userId" ).val()
        var neckName = $( "#info-neckName" ).val()
        var addr = $( "#info-addr" ).val()
        var mobile = $( "#info-mobile" ).val()
        $.post( "${rootPath}/gym/updateInfo", {"neckName":neckName,"userId":userId,"addr":addr,"mobile":mobile} , function ( data ) {
            if ( data.status == 1 ) {
                $('#info-alert').modal('close');
            }
            $('#uselogcontent').text( data.msg);
            $('#uselogBtn').click();
        }, "json" );
    }

</script>
</body>
</html>